﻿using System.Data.SqlTypes;
using NUnit.Framework;

namespace Fotia.SqlClr.Tests
{
	[TestFixture]
	public class FormatStringTests
	{
		[Test]
		public void CanFormatString0()
		{
			var input0 = new SqlString("Input0");
			var output = FormatString.FormatString0("Formatted:{0}", input0);

			Assert.AreEqual("Formatted:Input0", output.Value);
		}

		[Test]
		public void CanFormatString1()
		{
			var input0 = new SqlString("Input0");
			var input1 = new SqlString("Input1");
			var output = FormatString.FormatString1("Formatted:{0}{1}", input0, input1);

			Assert.AreEqual("Formatted:Input0Input1", output.Value);
		}

		[Test]
		public void CanFormatString2()
		{
			var input0 = new SqlString("Input0");
			var input1 = new SqlString("Input1");
			var input2 = new SqlString("Input2");
			var output = FormatString.FormatString2("Formatted:{0}{1}{2}", input0, input1, input2);

			Assert.AreEqual("Formatted:Input0Input1Input2", output.Value);
		}

		[Test]
		public void CanFormatString3()
		{
			var input0 = new SqlString("Input0");
			var input1 = new SqlString("Input1");
			var input2 = new SqlString("Input2");
			var input3 = new SqlString("Input3");
			var output = FormatString.FormatString3("Formatted:{0}{1}{2}{3}", input0, input1, input2, input3);

			Assert.AreEqual("Formatted:Input0Input1Input2Input3", output.Value);
		}

		[Test]
		public void CanFormatThousands()
		{
			var val = new SqlInt32(123456);
			var output = FormatString.FormatString0("{0:N0}", val);

			Assert.AreEqual("123,456", output.Value);
		}

		[Test]
		public void CanFormatSqlNull()
		{
			var output = FormatString.FormatString0("Formatted:{0}", SqlString.Null);

			Assert.AreEqual("Formatted:", output.Value);
		}

		[Test]
		public void CanFormatNull()
		{
			var output = FormatString.FormatString0("Formatted:{0}", null);

			Assert.AreEqual("Formatted:", output.Value);
		}

		[Test]
		public void CanFormatSqlInt16()
		{
			var input = new SqlInt16(101);
			var output = FormatString.FormatString0("Formatted:{0}", input);

			Assert.AreEqual("Formatted:101", output.Value);
		}

		[Test]
		public void CanFormatSqlInt32()
		{
			var input = new SqlInt32(101969);
			var output = FormatString.FormatString0("Formatted:{0}", input);

			Assert.AreEqual("Formatted:101969", output.Value);
		}

		[Test]
		public void CanFormatSqlInt64()
		{
			var input = new SqlInt64(101969843);
			var output = FormatString.FormatString0("Formatted:{0}", input);

			Assert.AreEqual("Formatted:101969843", output.Value);
		}

		[Test]
		public void CanFormatSqlSingle()
		{
			var input = new SqlSingle(101.962);
			var output = FormatString.FormatString0("Formatted:{0:F3}", input);

			Assert.AreEqual("Formatted:101.962", output.Value);
		}

		[Test]
		public void CanFormatSqlDouble()
		{
			var input = new SqlDouble(256.9765);
			var output = FormatString.FormatString0("Formatted:{0:E5}", input);

			Assert.AreEqual("Formatted:2.56977E+002", output.Value);
		}

		[Test]
		public void CanFormatSqlDateTime()
		{
			var input = new SqlDateTime(2009,05,23);
			var output = FormatString.FormatString0("Formatted:{0:dd MMM yyyy}", input);

			Assert.AreEqual("Formatted:23 May 2009", output.Value);
		}

		[Test]
		public void CanFormatSqlMoney()
		{
			var input = new SqlMoney(12345.678);
			var output = FormatString.FormatString0("Formatted:{0:N2}", input);

			Assert.AreEqual("Formatted:12,345.68", output.Value);
		}
	}
}